package com.wiseasy.smartpos.cashierdemo.util;

import android.text.TextUtils;
import java.math.BigDecimal;
import java.util.Currency;
import java.util.Set;


public class CurrencyUtils {
    public static String formatAmountByMinUnitWithStyleAndSymbol(String amount, int  currentNumericCode) {
        Currency currency = getCurrencySymbol(currentNumericCode);
        String number = amount;
        if (TextUtils.isEmpty(amount)) {
            number = "0";
        }
        return currency.getSymbol() + formatAmountByMinUnit(number, currency);
    }


    private static String formatAmountByMinUnit(String amount,  Currency currency ) {
        int decimalDigits = Currency.getInstance(currency.getCurrencyCode()).getDefaultFractionDigits();
        BigDecimal oldValue = new BigDecimal(amount);
        BigDecimal newValue = oldValue.movePointLeft(decimalDigits);
        return newValue.toString();
    }

    private static Currency getCurrencySymbol(int currentNumericCode) {
        Set<Currency> currencySet = Currency.getAvailableCurrencies();
        for (Currency currency : currencySet) {
            if (currency.getNumericCode() == currentNumericCode) {
                return currency;
            }
        }
        return null;
    }
}
